package com.openbravo.pos.scripting;

import java.io.StringReader;
import java.io.StringWriter;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.ParseErrorException;

class ScriptEngineVelocity
  implements ScriptEngine
{
  private static VelocityEngine m_ve = null;
  private VelocityContext c = null;

  public ScriptEngineVelocity()
    throws ScriptException
  {
    if (m_ve == null)
    {
      m_ve = new VelocityEngine();
      m_ve.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.NullLogSystem");
      m_ve.setProperty("ISO-8859-1", "UTF-8");
      m_ve.setProperty("input.encoding", "UTF-8");
      try
      {
        m_ve.init();
      }
      catch (Exception localException)
      {
        throw new ScriptException("Cannot initialize Velocity Engine", localException);
      }
    }
    this.c = new VelocityContext();
  }

  public void put(String paramString, Object paramObject)
  {
    this.c.put(paramString, paramObject);
  }

  public Object get(String paramString)
  {
    return this.c.get(paramString);
  }

  public Object eval(String paramString)
    throws ScriptException
  {
    if (m_ve == null)
      throw new ScriptException("Velocity engine not initialized.");
    StringWriter localStringWriter = new StringWriter();
    try
    {
      if (m_ve.evaluate(this.c, localStringWriter, "log", new StringReader(paramString)))
        return localStringWriter.toString();
      throw new ScriptException("Velocity engine unexpected error.");
    }
    catch (ParseErrorException localParseErrorException)
    {
      throw new ScriptException(localParseErrorException.getMessage(), localParseErrorException);
    }
    catch (MethodInvocationException localMethodInvocationException)
    {
      throw new ScriptException(localMethodInvocationException.getMessage(), localMethodInvocationException);
    }
    catch (Exception localException)
    {   throw new ScriptException(localException.getMessage(), localException);
    }
 
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.pos.scripting.ScriptEngineVelocity
 * JD-Core Version:    0.6.0
 */